package com.heima.wemedia.service.controller;

import com.heima.model.wemedia.entity.WmNewsMaterial;
import com.heima.wemedia.service.service.WmNewsMaterialService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 文章素材关联表(WmNewsMaterial)表控制层
 *
 * @author makejava
 * @since 2022-04-12 19:21:27
 */
@RestController
@RequestMapping("wmNewsMaterial")
public class WmNewsMaterialController {
    /**
     * 服务对象
     */
    @Resource
    private WmNewsMaterialService wmNewsMaterialService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<WmNewsMaterial> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.wmNewsMaterialService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param wmNewsMaterial 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<WmNewsMaterial> add(WmNewsMaterial wmNewsMaterial) {
        return ResponseEntity.ok(this.wmNewsMaterialService.insert(wmNewsMaterial));
    }

    /**
     * 编辑数据
     *
     * @param wmNewsMaterial 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<WmNewsMaterial> edit(WmNewsMaterial wmNewsMaterial) {
        return ResponseEntity.ok(this.wmNewsMaterialService.update(wmNewsMaterial));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Long id) {
        return ResponseEntity.ok(this.wmNewsMaterialService.deleteById(id));
    }

}

